import { Global, Module } from '@nestjs/common';
import { RedisService } from './redis.service';
import { createClient } from 'redis';

@Global()
@Module({
  providers: [
    RedisService,
    {
      provide: 'REDIS_CLIENT',
      async useFactory() {
          const client = createClient({
            socket: {
              host: 'localhost',
              // host: '10.1.22.152',
              // host: 'redis-container',
              port: 6379
            }
          })
          await client.connect()
          return client
      },
    }
  ],
  exports: [RedisService]
})
export class RedisModule {}
